home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / WCOMBOX.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  16.6 KB  |  488 lines

  1. /*************************************************************************
  2.  *
  3.  * WComboBox -- Wrapper for the combobox control.
  4.  *
  5.  *   Events:
  6.  *
  7.  *       BeginOwnerDraw -- Called before the first DrawItem.
  8.  *
  9.  *       Change -- Occurs whenever the edit box changes.
  10.  *
  11.  *       DataAvailable --
  12.  *
  13.  *       DataClose --
  14.  *
  15.  *       DataOpen --
  16.  *
  17.  *       DataRequest --
  18.  *
  19.  *       DoubleClick -- When an item in the list box is double-clicked.
  20.  *
  21.  *       DrawItem -- Called for owner-draw.
  22.  *
  23.  *       DropDown -- The list box is about to drop down.
  24.  *
  25.  *       DropDownSelect --
  26.  *
  27.  *       EndOwnerDraw -- Called after last DrawItem.
  28.  *
  29.  *       Select -- When an item in the list box has been selected.
  30.  *
  31.  *************************************************************************/
  32.  
  33. #ifndef _WCOMBOX_HPP_INCLUDED
  34. #define _WCOMBOX_HPP_INCLUDED
  35. #pragma once
  36.  
  37. #ifndef _WNO_PRAGMA_PUSH
  38. #pragma pack(push,8);
  39. #pragma enum int;
  40. #endif
  41.  
  42. #ifndef _WCONTROL_HPP_INCLUDED
  43. #  include "wcontrol.hpp"
  44. #endif
  45.  
  46. #ifndef _WLOCALE_HPP_INCLUDED
  47. #  include "wlocale.hpp"
  48. #endif
  49.  
  50. #ifndef _WDRAWITM_HPP_INCLUDED
  51. #  include "wdrawitm.hpp"
  52. #endif
  53.  
  54. #ifndef _WDATATRG_HPP_INCLUDED
  55. #  include "wdatatrg.hpp"
  56. #endif
  57.  
  58. //
  59. // ComboBox styles
  60. //
  61.  
  62. #define WCBSDefault           ((WStyle)0x50200201L) // WS_VISIBLE|CBS_HASSTRINGS|CBS_SIMPLE|WS_CHILD|WS_VSCROLL
  63. #define WCBSSimple            ((WStyle)0x00000001L) // CBS_SIMPLE
  64. #define WCBSDropDown          ((WStyle)0x00000002L) // CBS_DROPDOWN
  65. #define WCBSDropDownList      ((WStyle)0x00000003L) // CBS_DROPDOWNLIST
  66. #define WCBSOwnerDrawFixed    ((WStyle)0x00000010L) // CBS_OWNERDRAWFIXED
  67. #define WCBSOwnerDrawVariable ((WStyle)0x00000020L) // CBS_OWNERDRAWVARIABLE
  68. #define WCBSAutoHScroll       ((WStyle)0x00000040L) // CBS_AUTOHSCROLL
  69. #define WCBSOEMConvert        ((WStyle)0x00000080L) // CBS_OEMCONVERT
  70. #define WCBSSort              ((WStyle)0x00000100L) // CBS_SORT
  71. #define WCBSHasStrings        ((WStyle)0x00000200L) // CBS_HASSTRINGS
  72. #define WCBSNoIntegralHeight  ((WStyle)0x00000400L) // CBS_NOINTEGRALHEIGHT
  73. #define WCBSDisableNoScroll   ((WStyle)0x00000800L) // CBS_DISABLENOSCROLL
  74. #define WCBSUpperCase         ((WStyle)0x00002000L) // CBS_UPPERCASE
  75. #define WCBSLowerCase         ((WStyle)0x00004000L) // CBS_LOWERCASE
  76.  
  77. struct WComboBoxFDXData {
  78.     WStringArray                items;
  79.     WInt                        selected;
  80. };
  81.  
  82. class WCMCLASS WComboBox : public WControl {
  83.     WDeclareSubclass( WComboBox, WControl );
  84.     
  85.     public:
  86.  
  87.         /**************************************************************
  88.          * Constructors and Destructors
  89.          **************************************************************/
  90.  
  91.         WComboBox();
  92.     
  93.         ~WComboBox();
  94.  
  95.         /**************************************************************
  96.          * Properties
  97.          **************************************************************/
  98.  
  99.         // Count
  100.         //
  101.         //     Returns the number of items in the list box, or negative
  102.         //     if an error occurs.
  103.  
  104.         WInt GetCount() const;
  105.  
  106.         // DataColumns
  107.         //
  108.         //     DataTarget property
  109.  
  110.         WString GetDataColumns() const;
  111.         WBool   SetDataColumns( const WString & cols );
  112.  
  113.         // DataLookupColumns
  114.         //
  115.         //     DataTarget property
  116.  
  117.         WString GetDataLookupColumns() const;
  118.         WBool   SetDataLookupColumns( const WString & cols );
  119.  
  120.         // DataLookupSource
  121.         //
  122.         //     DataTarget property
  123.  
  124.         WDataSource *GetDataLookupSource() const;
  125.         WBool        SetDataLookupSource( WDataSource *source );
  126.  
  127.         // DataSource
  128.         //
  129.         //     DataTarget property
  130.  
  131.         WDataSource *GetDataSource() const;
  132.         WBool        SetDataSource( WDataSource *source );
  133.  
  134.         // FDXDataSource
  135.  
  136.         WBool SetFDXDataSource( WStringArray * fdxDataSource );
  137.         WBool SetFDXDataSource( WInt * fdxDataSource );
  138.  
  139.         // DroppedDown
  140.         //
  141.         //     Get/set the drop down state.  TRUE = dropped, FALSE = not.
  142.  
  143.         WBool GetDroppedDown() const;
  144.         WBool SetDroppedDown( WBool show );
  145.  
  146.         // EditSelection
  147.         //
  148.         //     The current selection in the edit control.  The
  149.         //     selection points start at 0 and occur between the characters.
  150.         //     Note that no value can be greater than 65534.  When setting,
  151.         //     set start=-1 to deselect everything, or set end=-1 to
  152.         //     select from start to end of text.
  153.  
  154.         WRange GetEditSelection() const;
  155.         WBool SetEditSelection( const WRange & editSelection );
  156.  
  157.         // ExtendedUI
  158.         //
  159.         //     Controls whether or not the combobox uses the extended UI.
  160.         //     If TRUE, the F4 key does nothing and the down arrow key
  161.         //     opens the drop-down list.  Otherwise the F4 key opens
  162.         //     the drop-down list and the down arrow key moves the
  163.         //     current selection.
  164.  
  165.         WBool GetExtendedUI() const;
  166.         WBool SetExtendedUI( WBool on );
  167.  
  168.         // Selected
  169.         //
  170.         //     Get/set the selected item in the list box.  A selected
  171.         //     value of -1 means nothing is selected.  Setting the value
  172.         //     to -1 clears the selected entry and the edit box.
  173.  
  174.         WInt GetSelected() const;
  175.         WBool SetSelected( WInt index );
  176.  
  177.         // SendDeleteItem
  178.         //
  179.         //     If TRUE, DeleteItem events will be triggered consistently
  180.         //     across all platforms if non-null user data has been
  181.         //     set for any items in the combobox.
  182.  
  183.         WBool GetSendDeleteItem() { return _sendDeleteItem; }
  184.         WBool SetSendDeleteItem( WBool set ) { _sendDeleteItem = set; return TRUE; }
  185.  
  186.         // Sort
  187.         //
  188.         //     Get/set the sort mode.
  189.  
  190.         WBool GetSort() const;
  191.         WBool SetSort( WBool sort, WBool clone=FALSE );
  192.  
  193.         // Locale (for type of sort)
  194.         //
  195.         //
  196.         WBool           SetLocale( WLocaleID locID );
  197.         WLocaleID       GetLocale();
  198.  
  199.         // TextLimit
  200.         //
  201.         //     Get/set the maximum # of characters the user can type
  202.         //     into the edit box. 0 or negative means set to maximum.
  203.  
  204.         WLong GetTextLimit() const;
  205.         WBool SetTextLimit( WLong limit );
  206.  
  207.  
  208.         /**************************************************************
  209.          * Methods
  210.          **************************************************************/
  211.  
  212.         // Add
  213.         //
  214.         //     Adds an item.  If itemNumber is set to >= 0, item is
  215.         //     inserted at the given location.  If the list is sorted
  216.         //     and itemNumber is set to -1, inserts in correct spot;
  217.         //     otherwise adds to the end.  Can also set optional
  218.         //     per-item data.
  219.         //     Returns the index of the item, or a negative value in
  220.         //     case of error.
  221.  
  222.         WInt Add( const WChar * string, WInt itemNumber=-1,
  223.                   void * itemUserData=NULL, WBool addInSortedOrder=TRUE );
  224.  
  225.         // Clear
  226.         //
  227.         //     Clear the edit box.
  228.  
  229.         void  Clear();
  230.  
  231.         // Copy
  232.         //
  233.         //     Copy the selected area into the clipboard.
  234.  
  235.         WBool Copy();
  236.  
  237.         // Cut
  238.         //
  239.         //     Copy the selected area into the clipboard then clear it.
  240.  
  241.         void  Cut();
  242.  
  243.         // DataAddLookupItem
  244.         //
  245.         //     Allows the user to manually fill the list with lookup items.
  246.         //     This is an alternative method to setting the DataLookupSource
  247.         //     and DataLookupColumns properties.
  248.  
  249.         WInt DataAddLookupItem( const WDataValue & value,
  250.                                 const WChar * string = NULL,
  251.                                 WInt itemNumber=-1, void * itemUserData=NULL,
  252.                                 WBool addInSortedOrder=TRUE );
  253.  
  254.         // DataFetchLookupItems
  255.         //
  256.         //      Forces the lookup items to be fetched from the database
  257.         //      (according to the DataLookupSource and DataLookupColumns
  258.         //      properties).
  259.         //      This is normally done when either data source is opened...
  260.  
  261.         WBool DataFetchLookupItems();
  262.  
  263.         // Delete
  264.         //
  265.         //     Deletes the specified item.  If an item's data is set,
  266.         //     invokes the WDeleteItemEvent event first.  Returns the count
  267.         //     of items remaining in the list, or negative if error occurs.
  268.  
  269.         WInt Delete( WInt itemNumber );
  270.  
  271.         // DeleteAll
  272.  
  273.         WBool DeleteAll ();
  274.  
  275.         // Find
  276.         //
  277.         //     Finds the first string that matches a given prefix.  The
  278.         //     search starts immediately AFTER the given index (use -1
  279.         //     to search from the beginning) and wraps when the bottom
  280.         //     is reached.  The search is not case-sensitive.  If exact
  281.         //     is specified, the string must match exactly, otherwise
  282.         //     a prefix match is done.  Returns the index of the match
  283.         //     or negative on error.
  284.  
  285.         WInt Find( const WChar *match, WInt startAfter=-1,
  286.                    WBool exact=FALSE ) const;
  287.  
  288.         // Paste
  289.         //
  290.         //     Paste the clipboard text into the current selection.
  291.  
  292.         void Paste();
  293.  
  294.         // Reset
  295.         //
  296.         //     Reset (clear) both the list box and edit box.
  297.  
  298.         void Reset();
  299.  
  300.         // Select
  301.         //
  302.         //     Find and select an item.  Searches for the first item whose
  303.         //     prefix matches (case-insensitive) the given string.  Returns
  304.         //     the index of the new selected item, or negative if an error
  305.         //     occurs.  If startAfter is -1, search starts at first item.
  306.  
  307.         WInt Select( const WChar * match, WInt startAfter=-1 );
  308.  
  309.         // Undo
  310.         //
  311.         //     Undo the last change to the edit box.
  312.  
  313.         WBool Undo();
  314.  
  315.         /**************************************************************
  316.          * Item Properties
  317.          **************************************************************/
  318.  
  319.         // DataLookupValue
  320.         //
  321.         //     Get the lookup value associated with the given list item.
  322.  
  323.         WDataValue GetDataLookupValue( WInt itemNumber ) const;
  324.  
  325.         // Text
  326.         //
  327.         //     Get the text of a specific item in the list.  First two
  328.         //     versions return a WString, which is set to a null string
  329.         //     if an error occurs.  Last version copies it into a buffer
  330.         //     and returns the length, or a negative value.
  331.  
  332.         WString GetText( WInt itemNumber ) const;
  333.  
  334.         // TextLength
  335.         //
  336.         //     Get the length of the text of an item in the list (without
  337.         //     the null character).  A negative value is returned in case
  338.         //     of error.
  339.  
  340.         WInt GetTextLength( WInt itemNumber ) const;
  341.  
  342.         // UserData
  343.         //
  344.         //     Get/set per-item data.  When getting data, a value of
  345.         //     ((void *)-1) for the itemUserData indicates an error.
  346.  
  347.         WBool  SetUserData( WInt itemNumber, void * itemData );
  348.         void * GetUserData( WInt itemNumber ) const;
  349.  
  350.         // Height
  351.         //
  352.         //     Get/set height of listbox items or the edit box.  If
  353.         //     itemNumber is -1, works on edit box, otherwise must be
  354.         //     0 if the WCBSOwnerDrawVariable flag is not set, otherwise
  355.         //     it is the index of the item.  For get, negative value
  356.         //     is returned to indicate error.
  357.  
  358.         WInt GetHeight( WInt itemNumber ) const;
  359.         WBool SetHeight( WInt itemNumber, WInt height );
  360.  
  361.         /**************************************************************
  362.          * Others
  363.          **************************************************************/
  364.  
  365.         virtual size_t GetTextLength() const;
  366.  
  367.         virtual WBool FDXIn();
  368.  
  369.         virtual WBool FDXOut();
  370.     
  371.         virtual WBool FillDragEventData( WDragEventData & event ) const;
  372.  
  373.         WBool DestroyEventHandler( WWindow * window, WEventData * event );
  374.  
  375.         WLong ProcessChildMessage( WWindowHandle hWnd, WUInt msg,
  376.                                    WUInt wParam, WLong lParam );
  377.  
  378.         virtual WBool ProcessMessage( const WMessage & msg,
  379.                                       WLong & returns );
  380.  
  381.         virtual WBool SetHeight( const WInt & height, WBool update=TRUE );
  382.         virtual WInt GetHeight() const;
  383.  
  384.         virtual WBool SetText( const WString & str );
  385.         virtual WString GetText() const;
  386.  
  387.         virtual WBool SetUserData( void * userData );
  388.         virtual void * GetUserData() const;
  389.  
  390.         virtual WBool ProcessCommand( WUInt id, WNotify code,
  391.                                       WNotifyInfo info, WLong & returns );
  392.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  393.                                    void * data=NULL );
  394.     
  395.         virtual WBool DefaultProcess( const WMessage & msg,
  396.                                       WLong & returns );
  397.     
  398.         virtual WBool      AttachToWindow( WWindowHandle hWnd, WBool destroy,
  399.                                            WBool subclass );
  400.         virtual WWindowHandle DetachFromWindow();
  401.     
  402.         virtual WStyle        GetDefaultStyle() const;
  403.         virtual WStyle        GetDefaultExtendedStyle() const;
  404.         virtual const WChar * InitializeClass();
  405.  
  406.         virtual WBool IgnoreDeleteItem();
  407.  
  408.         WBool DeleteItemHandler( WComboBox *, WDeleteItemEventData *ev );
  409.  
  410.         // Event handlers for the DataTarget
  411.  
  412.         WBool DataOpenHandler( WComboBox *, WDataOpenEventData *ev );
  413.         WBool DataCloseHandler( WComboBox *, WDataCloseEventData *ev );
  414.         WBool DataAvailableHandler( WComboBox *, WDataAvailableEventData *ev );
  415.         WBool DataRequestHandler( WComboBox *, WDataRequestEventData *ev );
  416.         WBool DataLookupItemHandler( WComboBox *, WDataLookupItemEventData *ev );
  417.  
  418.         /**************************************************************
  419.          * Overrides
  420.          **************************************************************/
  421.  
  422.         virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
  423.         virtual WBool SetFont( const WFont & font, WBool preserveSize=TRUE );
  424.         virtual WRect GetRectangle( WBool absolute=FALSE ) const;
  425.         virtual WBool Move( const WRect & rectangle, WBool update=TRUE );
  426.         virtual WBool Move( const WRect & rectangle, WDeferMoveHandle & dwp );
  427.         virtual WBool Move( const WPoint & point, WBool update=TRUE );
  428.         virtual WBool Move( const WPoint & point, WDeferMoveHandle & dwp );
  429.  
  430.         /**************************************************************
  431.          * Internal
  432.          **************************************************************/
  433.  
  434.     protected:
  435.  
  436.         WBool IndirectUserData( WBool indirect );
  437.  
  438.         WBool  SetRealUserData( WInt itemNumber, void * itemData );
  439.         void * GetRealUserData( WInt itemNumber ) const;
  440.  
  441.         WBool AllocLookup();
  442.  
  443.         void RemoveLookupItems();
  444.     
  445.         virtual WBool LoadWindow( WWindow * parent,
  446.                                   const WResourceID & id,
  447.                                   WModuleHandle module=_ApplicationModule );
  448.     
  449.         virtual WBool MakeWindow( WWindow * parent, WUInt id,
  450.                                   const WChar *className,
  451.                                   const WChar *title, const WRect & r,
  452.                                   WStyle wstyle, WStyle exStyle,
  453.                                   void * data=NULL );
  454.  
  455.         /**************************************************************
  456.          * Data members
  457.          **************************************************************/
  458.  
  459.     protected:
  460.  
  461.         WWindowHandle       _editChild;
  462.         WCallbackProc       _editWndProc;
  463.         WWindowHandle       _listChild;
  464.         WCallbackProc       _listWndProc;
  465.         WLong               _textLimit;
  466.         WBool               _indirectUserData;
  467.         WDataLookup *       _dataLookup;
  468.         WDataTargetCell *   _dataTarget;
  469.         WInt                _initialValue;
  470.         WBool               _wasEnabled;
  471.         WBool               _wasPainting;
  472.         WBool               _ignoreChange;
  473.         WStringArray *      _fdxDataSourceStringArray;
  474.         WInt *              _fdxDataSourceInt;
  475.         WInt                _realHeight;
  476.         WBool               _userDataWasSet;
  477.         WBool               _sendDeleteItem;
  478.         WBool               _ignoreDeleteItem;
  479. };
  480.  
  481.  
  482. #ifndef _WNO_PRAGMA_PUSH
  483. #pragma enum pop;
  484. #pragma pack(pop);
  485. #endif
  486.  
  487. #endif // _WCOMBOX_HPP_INCLUDED
  488.